package com.localization;

import android.util.Log;

/**
 * Created by Edward on 2017/1/7.
 * 数据缓存区
 */
public class GatawayBuffer {
    private byte[] fifo  = new byte[1024];
    private int postion = 0;
    private int length = 1024;

    public  int setBuffer(byte[] data,int size)
    {
        postion=0;
        int cnt = postion;
        int len = postion+size;
        int index = 0;
        if(len > length)
            return -1;

        for(cnt = postion,index = 0;cnt< len;cnt++,index++)
        {
            fifo[cnt] = data[index];
            postion++;
        }

        Log.d("GatawayBuffer:",Utils.printHexString(fifo,postion+1)+"--"+len);



        return len;
    }

    public void setCleanBuf()
    {
        this.postion = 0;
    }

    public void setMove(int packetPos)
    {
        if(packetPos > postion)
            return;

        int movelen = postion-packetPos;
        for(int cnt = 0;cnt <movelen;cnt++)
        {
            fifo[cnt] = fifo[packetPos+cnt];
        }
        postion = movelen;
    }

    public int getPostion()
    {
        return this.postion;
    }

    public int getLength()
    {
        return this.length;
    }

    public byte[] getBuffer()
    {
        return this.fifo;
    }


}
